<!-- @Description:front/src/componentssdk.vue @author:378237242@qq.com @date:2023/12/12 -->
<template>
  <n-space vertical>
    <n-space>
      <n-button type="primary" @click="recordStart">开始</n-button>
      <n-button type="info" @click="recordOff">结束</n-button>
      <button @click.ctrl="onClick">A</button>
    </n-space>

    <!--<audio :src="audioData" controls></audio>-->
  </n-space>
</template>

<script setup lang="ts">
import VoiceControl from "@dqwl/voicecontrol-sdk";
import { ref } from "vue";
// 当前按钮链接状态
const curAsrBtnStatus = ref("CLOSED");
const vcInstance = new VoiceControl({
  appid: "554602d6",
  api_key: "9d005ff4e64b5af1c11d23b52e43c925",
  api_secret: "ZDI5MzMzM2I3NjkwMjJlZjU4MTQ0MDli",
  server_url: "http://127.0.0.1:7001/api/npl",
});
vcInstance.onStateChange((state) => {
  console.log(`onStateChange at ${new Date().getTime()} ${state}`);
});
const recordStart = () => {
  if (curAsrBtnStatus.value === "CLOSED") {
    vcInstance.start();
  } else if (curAsrBtnStatus.value === "OPEN") {
    // 结束录音
    vcInstance.stop();
  }
};
const recordOff = () => {
  vcInstance.stop();
};
vcInstance.onStateChange((state) => {
  console.log(state);
});
vcInstance.onError((e) => {
  console.log(e);
});
vcInstance.onResultTextChange((text) => {
  console.log(text);
});
vcInstance.onResultCommand((command) => {
  console.log(command);
});
const onClick = () => {
  console.log("a");
};
</script>

<style scoped></style>
